package org.elanfox.intellicommunity.biz.entity.equipment;

import lombok.Getter;
import lombok.Setter;
import org.elanfox.intellicommunity.biz.entity.Base2PO;
import org.elanfox.intellicommunity.common.constant.DataConstant;
import org.elanfox.intellicommunity.common.ienum.EquipmentEnum;
import org.springframework.data.jpa.domain.support.AuditingEntityListener;

import javax.persistence.Column;
import javax.persistence.EntityListeners;
import javax.persistence.MappedSuperclass;
import java.time.LocalDateTime;

/**
 * 设备PO
 *
 * @author loutianxi
 * @date 2019-12-03
 */
@Setter
@Getter
@EntityListeners(AuditingEntityListener.class)
@MappedSuperclass
public class EquipmentPO extends Base2PO {

    /**
     * 设备编号
     */
    @Column(name = "no")
    private Long no;
    /**
     * 设备版本
     */
    @Column(name = "version")
    private String version;
    /**
     * 设备类型
     */
    @Column(name = "type")
    private EquipmentEnum.TypeEnum type;
    /**
     * 设备电压状态
     */
    @Column(name = "voltage_status")
    private EquipmentEnum.VoltageStatusEnum voltageStatus;
    /**
     * 设备报警状态（1.报警，0.未报警）
     */
    @Column(name = "status")
    private boolean status;
    /**
     * 设备防拆状态（1.正常，0异常）
     */
    @Column(name = "dismantle_status")
    private boolean dismantleStatus;
    /**
     * 在线状态（1.在线，0.离线）
     */
    @Column(name = "online_status")
    private boolean onlineStatus;
    /**
     * 启用状态（1.启用，0.禁用）
     */
    @Column(name = "enable")
    private boolean enable;
    /**
     * 设备描述
     */
    @Column(name = "descr")
    private String describe;

    public void initStatus() {
        LocalDateTime now = LocalDateTime.now();
        this.status = false;
        this.dismantleStatus = true;
        this.voltageStatus = EquipmentEnum.VoltageStatusEnum.STATUS_0;
        this.onlineStatus = true;
        this.enable = true;
        setCreateTime(now);
        setUpdateTime(now);
    }

    public String getEnableStyle() {
        return enable ? DataConstant.GREEN_STYLE : DataConstant.RED_STYLE;
    }

    public String getOnlineStyle() {
        return onlineStatus ? DataConstant.GREEN_STYLE : DataConstant.RED_STYLE;
    }

    public String getStatusStyle() {
        return status ? DataConstant.RED_STYLE : DataConstant.GREEN_STYLE;
    }

    public String getDismantleStatusStyle() {
        return dismantleStatus ? DataConstant.GREEN_STYLE : DataConstant.RED_STYLE;
    }

    public String getVoltageStatusStyle() {
        String str = "";
        switch (voltageStatus) {
            case STATUS_0:
                str = DataConstant.GREEN_STYLE;
                break;
            case STATUS_1:
                str = DataConstant.RED_STYLE;
                break;
            default:
                break;
        }
        return str;
    }
}
